#include "../begonia.h"
#include "3_1_specialbullet.h"
#include "../base/scene.h"

s3_1_specialbullet::s3_1_specialbullet(double tx,double ty,double tr,double tvx,double tvy,bullet *h):bullet(tx,ty,tr,tvx,tvy,h)
    {
    }
void s3_1_specialbullet::clone(bullet *h)
    {
        s3_1_specialbullet *a=new s3_1_specialbullet(x,y,r,vx,vy,h);
        a->c_r=c_r;
        a->c_g=c_g;
        a->c_b=c_b;
    }
bool s3_1_specialbullet::move()
{
    for(bullet *a=f.head.next,*a2;a!=&f.head;a=a2)
    {
        a2=a->next;
        if(a->c_r==c_r&&a->c_g==c_g&&a->c_b==c_b)
        {
            double t0=atan2(a->y-y,a->x-x),d2=sqr(a->x-x)+sqr(a->y-y);
            if(d2<25) d2=25;
            a->vx+=cos(t0)*25/d2*(t-tlast);
            a->vy+=sin(t0)*25/d2*(t-tlast);
        }
        else if(a->c_r==1.0-c_r&&a->c_g==1.0-c_g&&a->c_b==1.0-c_b)
        {
            double t0=atan2(a->y-y,a->x-x),d2=sqr(a->x-x)+sqr(a->y-y);
            if(d2<25) a->x=a->y=a->vx=a->vy=-100;
            else
            {
                a->vx-=cos(t0)*25/d2*(t-tlast);
                a->vy-=sin(t0)*25/d2*(t-tlast);
            }
        }  
    }
    return true;
}
